package com.th.supcom.pds.impl.service.internal.phamapply.chain;

import net.carefx.framework.exception.BusinessException;

import org.apache.commons.chain.impl.ChainBase;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;

import com.th.supcom.pds.impl.service.internal.phamapply.command.PhamDispenseContext;

/**
 * 药房退药 责任链
 * 
 * @author yzhang
 */
public class InPharmacyReturnServiceChain implements BeanFactoryAware
{
    private BeanFactory m_beanFactory;
    private PhamDispenseContext m_phamDispenseContext;

    /**
     * 带药退药
     */
    public void inPharmacyReturnWithDrug ()
    {
        try
        {
            ChainBase chainBase = createChain ("inPharmacyReturnWithDrugChain");
            chainBase.execute (m_phamDispenseContext);
        }
        catch (Exception exc)
        {
            throw new BusinessException (exc.getMessage (), exc);
        }
    }

    /**
     * 不带药退药
     */
    public void inPharmacyReturnWithoutDrug ()
    {
        try
        {
            ChainBase chainBase = createChain ("inPharmacyReturnWithoutDrugChain");
            chainBase.execute (m_phamDispenseContext);
        }
        catch (Exception exc)
        {
            throw new BusinessException (exc.getMessage (), exc);
        }
    }

    protected ChainBase createChain (String chainName)
    {
        return (ChainBase) this.m_beanFactory.getBean (chainName);
    }

    @Override
    public void setBeanFactory (BeanFactory beanFactory) throws BeansException
    {
        this.m_beanFactory = beanFactory;
    }

    public PhamDispenseContext getPhamDispenseContext ()
    {
        return m_phamDispenseContext;
    }

    public void setPhamDispenseContext (PhamDispenseContext phamDispenseContext)
    {
        m_phamDispenseContext = phamDispenseContext;
    }

}
